package com.luo.dao.impl;

import com.luo.dao.CartMappers;
import com.luo.model.Carts;
import com.luo.model.CartsVO;
import com.luo.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Map;

/**
 * 功能：
 * 作者：Luo。
 * 日期：2024/2/13 16:07
 */
public class CartDaoImpl implements CartMappers {
    @Override
    public List<Carts> queryCartsById(String id) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        CartMappers mapper = sqlSession.getMapper(CartMappers.class);
        List<Carts> carts = mapper.queryCartsById(id);
        sqlSession.close();
        return carts;
    }

    @Override
    public int addOneCart(Map map) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        CartMappers mapper = sqlSession.getMapper(CartMappers.class);
        int i = mapper.addOneCart(map);
        sqlSession.commit();
        sqlSession.close();
        return i;
    }

    @Override
    public int deleteOneCartByIds(Map map) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        CartMappers mapper = sqlSession.getMapper(CartMappers.class);
        int i = mapper.deleteOneCartByIds(map);
        sqlSession.commit();
        sqlSession.close();
        return i;
    }

    @Override
    public int updateOneCartById(Map map) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        CartMappers mapper = sqlSession.getMapper(CartMappers.class);
        int i = mapper.updateOneCartById(map);
        sqlSession.commit();
        sqlSession.close();
        return i;
    }

    @Override
    public int updateOneCartSelectedById(final Map map) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        CartMappers mapper = sqlSession.getMapper(CartMappers.class);
        int i = mapper.updateOneCartSelectedById(map);
        sqlSession.commit();
        sqlSession.close();
        return i;
    }

    @Override
    public List<CartsVO> queryCartsVOByUserId(String id) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        CartMappers mapper = sqlSession.getMapper(CartMappers.class);
        List<CartsVO> list = mapper.queryCartsVOByUserId(id);
        sqlSession.commit();
        sqlSession.close();
        return list;
    }

    @Override
    public Carts queryCartsByCartsId(String id) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        CartMappers mapper = sqlSession.getMapper(CartMappers.class);
        Carts carts = mapper.queryCartsByCartsId(id);
        sqlSession.commit();
        sqlSession.close();
        return carts;
    }
}
